
use price_budget::runtime::BudgetRuntime;
use price_common::bootstrap::{
    BootstrapArtifacts, ProjectPhase, ProjectProfile
};
use price_budget::bootstrap::BootstrapRegistryBuilder;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // 使用新的 API：直接从 Bootstrap 产物创建运行时
    let artifacts = build_bootstrap_artifacts().await;
    let mut runtime = BudgetRuntime::from_bootstrap(artifacts).await?;
   let doc= runtime.doc().await?;

    runtime.export("./aaa.mff".into()).await?;
    dbg!(serde_json::to_string(&doc));
/*    let engine = runtime.get_rules_engine().await.unwrap();
    let res = engine.evaluate("test", json!({"value":10}).into()).await.unwrap();
    info!("res: {:?}", res);*/
    runtime.destroy().await?;
    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
    Ok(())
}

/// 閫氳繃寮曞鍔犺浇鍣ㄧ粍瑁?PriceEditorOptions
#[allow(dead_code)]
async fn build_bootstrap_artifacts() -> BootstrapArtifacts {
    let profile = ProjectProfile::builder()
        .project_id("123456789")
        .phase(ProjectPhase::Budget)
        .metadata("rules","/rules")
        .build().expect("invalid project profile");
    let registry =BootstrapRegistryBuilder::new().build();
    let loader = registry.build_loader(&profile);
    loader.bootstrap(profile).await.expect("bootstrap loader should succeed")
}
